//
//  WXClient.m
//  BossZP
//
//  Created by Raymond~ on 14-4-16.
//  Copyright (c) 2014年 com.dlnu.*. All rights reserved.
//

#import "WXClient.h"

#import "UIImageView+WebCache.h"
#import "OauthKeys.h"
@implementation WXClient

+ (WXClient *)sharedClient{
    static WXClient * singleClient;
    static dispatch_once_t pred;
    dispatch_once(&pred,^{
        singleClient=[[self alloc] initSingleton];
    } );
    return singleClient;
}
- (id)initSingleton
{
    if(self=[super init]){
//        [WXApi registerApp:WXAPP_ID];
    }
    return self;
}
- (void) sendTextContent:(NSString *)textContent
                andScene:(int)scene{
    SendMessageToWXReq* req = [[SendMessageToWXReq alloc] init];
    req.text = textContent;
    req.bText = YES;
    req.scene = scene;
    [WXApi sendReq:req];
}

- (BOOL)handleOpenURL:(NSURL*)url{
    
    return [WXApi handleOpenURL:url delegate:self];
}
- (void)sendLinkContentWithURlStr:(NSString *)urlStr
                         andTitle:(NSString *)title
                   andDescription:(NSString *)description
                         andImage:(UIImage *)image
                         andScene:(int)scene {
    
    WXMediaMessage *message = [WXMediaMessage message];
    message.title = title;
    message.description = description;
    [message setThumbImage:image];
    
    
    
    WXWebpageObject *ext = [WXWebpageObject object];
    ext.webpageUrl = urlStr;
    message.mediaObject = ext;
    
    
    
    SendMessageToWXReq* req = [[SendMessageToWXReq alloc] init];
    req.bText = NO;
    req.message = message;
    req.scene = scene;
    [WXApi sendReq:req];
}

- (void)sendLinkContentWithURlStr:(NSString *)urlStr
                         andTitle:(NSString *)title
                      andImageURL:(NSString *)imageURL
                       andDescription:(NSString *)description
                         andScene:(int)scene {

    UIImage *img = [[SDImageCache  sharedImageCache] imageFromDiskCacheForKey:imageURL];

    [[WXClient sharedClient]sendLinkContentWithURlStr:urlStr
                                             andTitle:title
                                       andDescription:description
                                             andImage:img
                                             andScene:scene];

}

@end
